package com.coin.config.mybatisplus;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.core.incrementer.IKeyGenerator;
import com.baomidou.mybatisplus.extension.incrementer.H2KeyGenerator;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.*;
import org.springframework.context.annotation.*;

/**
 * @Auther: 李 力
 * @Date: 2025/5/24
 * @Description: com.coin.config.mybatisplus
 * @version: 1.0
 */
@Configuration
public class MybatisPlusConfig {

    /*
     * 分页插件和乐观锁插件
     * */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        mybatisPlusInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        return mybatisPlusInterceptor;
    }


    /**
     * Id 生成:特殊的一些类使用
     */
    @Bean
    public IKeyGenerator iKeyGenerator() {
        return new H2KeyGenerator();
    }
}
